﻿#include "precomp.h"
#include "global_state.h"
#include "background.h"
#include "bullet.h"
#include "enemy.h"
#include "player.h"
#include "bonus.h"
#include "resources.h"
#include "sound.h"
#include "gametimer.h"
#include "dialog.h"
#include "replay.h"
#include "ring_renderer.h"
#include "ending.h"
#include "framerate_counter.h"
#include <math.h>
#include "bulletml.h"

class Application
{
//!Operations:
public:
	//: Main function for the application.
	virtual int main(const std::vector<CL_String> &args);

	void on_window_close();
	void on_window_resize(int width, int height);
	void on_input_up(const CL_InputEvent &key, const CL_InputState &state);
	void on_input_down(const CL_InputEvent &key, const CL_InputState &state);
	void on_joystick_axis_move(const CL_InputEvent &joy, const CL_InputState &state);
	void on_joystick_down(const CL_InputEvent &key, const CL_InputState &state);

	void SaveConfig();
	void LoadConfig();
	void CreateNewConfig();
	bool ConfigExists();
	void Screenshot();

	void UnloadLevel();
	void SetStartParameters();

	void ResetInputs();
	void ReplaceKey(int before, int after);

	void DrawStats(CL_Font &_font);
	void DrawBossStats(CL_Font &_font);
	void DrawBossBackground(float time);
	void FillBorders();
	void ShowVersion(CL_Font &_font);

	CL_String get_text_line(CL_String name);

	CL_String get_option_string(CL_String name);
	float get_option_float(CL_String name);
	int get_option_int(CL_String name);
	void CheckTimeStart();
	void CheckTime(CL_String mark);

	CL_String get_zeroed_int(int n, int zeros);

	void _ResizeWindow(CL_DisplayWindow &win);
	void _RecreateWindow(CL_DisplayWindow &win);
	void _ReconnectGC(CL_DisplayWindow &win);

//!Implementation:
private:
	bool quit;

	CL_DisplayWindowDescription win_desc;
	//CL_DisplayWindow window;
	CL_GraphicContext gc;
	CL_InputContext ic;
	CL_BlendMode blendmode;
	CL_FrameBuffer framebuffer1;
	CL_Texture copy_texture1;

	CL_Slot slot_quit;
	CL_Slot slot_win_resize;
	CL_Slot slot_input_up;
	CL_Slot slot_input_down;
	CL_Slot slot_joy_down;
	CL_Slot slot_axis_move;
	int last_joy_x;
	int last_joy_y;
	float last_pad;
	float last_joy_time;

	CL_ResourceManager resources;
	CL_ResourceManager graphic_resources;
	CL_ResourceManager player_resources;
	CL_ResourceManager text_resources;
	CL_ResourceManager sound_resources;
	CL_ResourceManager music_resources;
	CL_ResourceManager pattern_resources;
	CL_ResourceManager level_resources;

	// Графика интерфейса и прочего
	CL_Sprite *splash_screen;
	CL_Sprite *screen_mask;
	CL_Sprite *lang_select;
	CL_Sprite *menu_screen;
	CL_Sprite *menu_nitori;
	CL_Sprite *menu_shadow;
	CL_Sprite *menu_title1;
	CL_Sprite *menu_title2;
	CL_Sprite *menu_list;
	CL_Sprite *menu_list_tips;
	CL_Sprite *menu_options;
	CL_Sprite *menu_keys;
	CL_Sprite *menu_options_tips;
	CL_Sprite *game_screen;
	CL_Sprite *game_stats;
	RingSprite *magic_rings;

	// Параметры интерфейса
	int menu_selection;
	int next_menu_selection;
	int current_menu_selection; // горизонтальный выбор в опциях
	int menu_moving;
	int menu_selected;
	int menu_after_splash;
	int menu_finished_work;

	// Обработанный пользовательский ввод
	int keys_up;
	int keys_down;
	int keys_left;
	int keys_right;
	int keys_fire;
	int keys_aim;
	int keys_bomb;
	int keys_cancel;
	int keys_fullscreen;
	int keys_resize_event;
	int keys_joy; // текущая нажатая клавиша пада + 1
	int keys_screenshot;

	CL_Size new_size;

	float temp_float1;
	float temp_float2;
	float temp_float3;
	CL_String temp_string;
	CL_Colorf temp_color;

	float performance_time_check;
};
